package com.ZeroCarbon.domain.dto;

import cn.hutool.core.bean.BeanUtil;
import com.ZeroCarbon.domain.po.Post;
import com.ZeroCarbon.utils.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 记录编辑类
 *
 * @since 2024-11-20
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PostEditDTO {
    /**
     * 记录id
     */
    private String id;

    /**
     * 图片集
     */
    private List<String> images;

    /**
     * 标题
     */
    private String title;

    /**
     * 正文内容
     */
    private String content;

    /**
     * 标签
     */
    private List<String> tags;

    /**
     * 是否私密
     */
    private boolean privateCondition;

    /**
     * PostEditDTO转PO
     */
    public Post toPost() {
        Post post = BeanUtil.copyProperties(this, Post.class);
        return post.setTagsJson(JsonUtils.ObjectToJson(tags))
                //设置最后修改时间
                .setLastTime(LocalDateTime.now())
                //设置私密性
                .setPrivateCondition(privateCondition);
    }
}
